import { asyncRoutes, constantRoutes } from '@/router/index.js'
// 声明全局变量的地方
const state = {
  routes: []
}
// 用来修改state数据的地方
const mutations = {
  setRoutes(state, routes) {
    state.routes = [...constantRoutes, ...routes]
  }
}

// 异步简介修改state数据的地方，通过mutations来修改
const actions = {
  filterRoutes(store, menus) {
    const routes = asyncRoutes.filter(item => {
      if (menus.indexOf(item.name) !== -1) {
        return item
      }
    })
    store.commit('setRoutes', routes)
    return routes
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
